#include <soc/soc_t10/jzm_jpeg_dec.h>

void T20_JPEGD_SliceInit(_JPEGD_SliceInfo *s)
{
  unsigned int i;
  volatile unsigned int *chn = (volatile unsigned int *)s->des_va;

  GEN_VDMA_ACFG(chn, TCSM_FLUSH, 0, 0x0);

  /* Open clock configuration */
  GEN_VDMA_ACFG(chn, REG_JPGC_GLBI, 0, OPEN_CLOCK);

  /**************************************************
   Huffman MIN Table configuration
  *************************************************/
  for(i=0; i<HUFFMIN_LEN; i++)
    GEN_VDMA_ACFG(chn, REG_JPGC_HUFM+i*4, 0, s->huffmin[i]);

  /**************************************************
   Huffman Base Table configuration
  *************************************************/
  for(i=0; i<HUFFBASE_LEN; i++)
    GEN_VDMA_ACFG(chn, REG_JPGC_HUFB+i*4, 0, s->hea[i]);

  /**************************************************
   Huffman Symbol Table configuration
  *************************************************/
  for(i=0; i<HUFFSYM_LEN; i++)
    GEN_VDMA_ACFG(chn, REG_JPGC_HUFS+i*4, 0, s->heb[i]);

  /**************************************************
   Quantization Table configuration
  *************************************************/
  for(i=0; i<QMEM_LEN; i++)
    GEN_VDMA_ACFG(chn, REG_JPGC_QMEM+i*4, 0, s->qt[i / 64][i % 64]);

  /**************************************************
   REGs configuration
  *************************************************/
  GEN_VDMA_ACFG(chn, REG_JPGC_STAT, 0, STAT_CLEAN);
  GEN_VDMA_ACFG(chn, REG_JPGC_BSA, 0, (intptr_t)s->bsa);
  GEN_VDMA_ACFG(chn, REG_JPGC_P0A, 0, (intptr_t)s->dst_y);
  GEN_VDMA_ACFG(chn, REG_JPGC_P1A, 0, (intptr_t)s->dst_c);

  GEN_VDMA_ACFG(chn, REG_JPGC_NMCU, 0, s->regs[1]);
  GEN_VDMA_ACFG(chn, REG_JPGC_NRSM, 0, s->regs[2]);

  GEN_VDMA_ACFG(chn, REG_JPGC_P0C, 0, s->regs[3]);
  GEN_VDMA_ACFG(chn, REG_JPGC_P1C, 0, s->regs[4]);
  GEN_VDMA_ACFG(chn, REG_JPGC_P2C, 0, s->regs[5]);
  GEN_VDMA_ACFG(chn, REG_JPGC_P3C, 0, s->regs[6]);

  GEN_VDMA_ACFG(chn, REG_JPGC_GLBI, 0, (YUV420PVH   |
			  ((s->regs[0] & 0x3) << 4)				|
			  JPEG_DEC		/* DE */				|
			  (s->regs[0] & 0x4) /* FE */			|
			  JPGC_EN));

  GEN_VDMA_ACFG(chn, REG_JPGC_TRIG, VDMA_ACFG_TERM, JPGC_BS_TRIG | JPGC_PP_TRIG | JPGC_CORE_OPEN);
}
